home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / MACVOGL- / EXAMPLES / POLY.C < prev    next >
C/C++ Source or Header  |  1992-07-19  |  3KB  |  191 lines

  1. #include <stdio.h>
  2.  
  3. #ifdef SGI
  4. #include "gl.h"
  5. #include "device.h"
  6. #else
  7. #include "vogl.h"
  8. #include "vodevice.h"
  9. #endif
  10.  
  11. /*
  12.  *    An array of points for a polygon
  13.  */
  14. static Coord    parray[][3] = {
  15.     {-8.0, -8.0, 0.0},
  16.     {-5.0, -8.0, 0.0},
  17.     {-5.0, -5.0, 0.0},
  18.     {-8.0, -5.0, 0.0}
  19. };
  20.  
  21. /*
  22.  * drawpoly
  23.  *
  24.  *    draw some polygons
  25.  */
  26. void
  27. drawpoly()
  28. {
  29.     float    vec[3];
  30.     short    val;
  31.  
  32.     color(YELLOW);
  33.  
  34.     /*
  35.      * Draw a polygon using poly, parray is our array of
  36.      * points and 4 is the number of points in it.
  37.      */
  38.     poly(4L, parray);
  39.  
  40.     color(GREEN);
  41.  
  42.     /*
  43.      * Draw a 5 sided figure by using bgnpolygon, v3d, and endpolygon
  44.      */
  45.     polymode(PYM_LINE);
  46.     bgnpolygon();
  47.         vec[0] = 0.0;
  48.         vec[1] = 0.0;
  49.         vec[2] = 0.0;
  50.         v3f(vec);
  51.         vec[0] = 3.0;
  52.         vec[1] = 0.0;
  53.         vec[2] = 0.0;
  54.         v3f(vec);
  55.         vec[0] = 3.0;
  56.         vec[1] = 4.0;
  57.         vec[2] = 0.0;
  58.         v3f(vec);
  59.         vec[0] = -1.0;
  60.         vec[1] = 5.0;
  61.         vec[2] = 0.0;
  62.         v3f(vec);
  63.         vec[0] = -2.0;
  64.         vec[1] = 2.0;
  65.         vec[2] = 0.0;
  66.         v3f(vec);
  67.     endpolygon();
  68.  
  69.     color(MAGENTA);
  70.  
  71.     /*
  72.      * draw a sector representing a 1/4 circle
  73.      */
  74.     arc(1.5, -7.0, 3.0, 0, 900);
  75.  
  76.     move2(1.5, -7.0);
  77.     draw2(1.5, -4.0);
  78.  
  79.     move2(1.5, -7.0);
  80.     draw2(4.5, -7.0);
  81.  
  82.     qread(&val);
  83. }
  84.  
  85. /*
  86.  * drawpolyf
  87.  *
  88.  *    draw some filled polygons
  89.  */
  90. void
  91. drawpolyf()
  92. {
  93.     short    val;
  94.  
  95.     color(YELLOW);
  96.  
  97.     polymode(PYM_FILL);
  98.  
  99.     /*
  100.      * Draw a polygon using poly, parray is our array of
  101.      * points and 4 is the number of points in it.
  102.      */
  103.     polf(4L, parray);
  104.  
  105.     color(GREEN);
  106.  
  107.     /*
  108.      * Draw a filled 5 sided figure by using pmv, pdr and pclos.
  109.      */
  110.     pmv(0.0, 0.0, 0.0);
  111.         pdr(3.0, 0.0, 0.0);
  112.         pdr(3.0, 4.0, 0.0);
  113.         pdr(-1.0, 5.0, 0.0);
  114.         pdr(-2.0, 2.0, 0.0);
  115.     pclos();
  116.  
  117.     color(MAGENTA);
  118.  
  119.     /*
  120.      * draw a filled sector representing a 1/4 circle
  121.      */
  122.     arcf(1.5, -7.0, 3.0, 0, 900);
  123.  
  124.     qread(&val);
  125. }
  126.  
  127. /*
  128.  * Using polygons, hatching, and filling.
  129.  */
  130. main()
  131. {
  132.     short    val;
  133.  
  134.     winopen("poly");
  135.  
  136.     unqdevice(INPUTCHANGE);
  137.     qdevice(KEYBD);        /* enable keyboard */
  138.  
  139.     color(BLACK);        /* clear to black */
  140.     clear();
  141.  
  142.     /*
  143.      * world coordinates are now in the range -10 to 10
  144.      * in x, y, and z. Note that positive z is towards us.
  145.      */
  146.     ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);
  147.  
  148.     color(YELLOW);
  149.  
  150.     /*
  151.      * write out the string "Polygon from poly()" in the
  152.      * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
  153.      * 0.5 units high.
  154.      */
  155.     hfont("futura.m");
  156.     hboxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()/ polf()");
  157.  
  158.     color(GREEN);
  159.  
  160.     /*
  161.      * write out a scaled string starting at (0.0, 6.0)
  162.      */
  163.     hboxtext(0.0, 6.0, 4.5, 0.5, "Polygon from bgnpoly()/ endpoly()");
  164.     hboxtext(0.0, 5.0, 4.5, 0.5, "             pmv()/ pdr()/ pclos()");
  165.  
  166.     color(MAGENTA);
  167.  
  168.     /*
  169.      * write out a scaled string starting at (0.0, 6.0)
  170.      */
  171.     hboxtext(3.5, -3.5, 1.9, 0.5, "Arc/ Arcf");
  172.  
  173.     /*
  174.      * draw some wire frame polygons
  175.      */
  176.     drawpoly();
  177.  
  178.     /*
  179.      *  rotate so the next polygons will appear in a different place.
  180.      */
  181.     rot(20.0, 'x');
  182.     rot(30.0, 'y');
  183.  
  184.     /*
  185.      * draw some filled polygons.
  186.      */
  187.     drawpolyf();
  188.  
  189.     gexit();
  190. }
  191.